package com.stylefeng.guns.modular.orgnazation.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Orgnazation;
import com.stylefeng.guns.modular.orgnazation.service.IOrgnazationService;

/**
 * 合作单位控制器
 *
 * @author fengshuonan
 * @Date 2018-07-29 15:38:30
 */
@Controller
@RequestMapping("/orgnazation")
public class OrgnazationController extends BaseController {

    private String PREFIX = "/orgnazation/orgnazation/";

    @Autowired
    private IOrgnazationService orgnazationService;

    /**
     * 跳转到合作单位首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "orgnazation.html";
    }

    /**
     * 跳转到添加合作单位
     */
    @RequestMapping("/orgnazation_add")
    public String orgnazationAdd() {
        return PREFIX + "orgnazation_add.html";
    }

    /**
     * 跳转到修改合作单位
     */
    @RequestMapping("/orgnazation_update/{orgnazationId}")
    public String orgnazationUpdate(@PathVariable Integer orgnazationId, Model model) {
        Orgnazation orgnazation = orgnazationService.selectById(orgnazationId);
        model.addAttribute("item",orgnazation);
        LogObjectHolder.me().set(orgnazation);
        return PREFIX + "orgnazation_edit.html";
    }

    /**
     * 获取合作单位列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return orgnazationService.selectList(null);
    }

    /**
     * 新增合作单位
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Orgnazation orgnazation) {
        orgnazationService.insert(orgnazation);
        return SUCCESS_TIP;
    }

    /**
     * 删除合作单位
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer orgnazationId) {
        orgnazationService.deleteById(orgnazationId);
        return SUCCESS_TIP;
    }

    /**
     * 修改合作单位
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Orgnazation orgnazation) {
        orgnazationService.updateById(orgnazation);
        return SUCCESS_TIP;
    }

    /**
     * 合作单位详情
     */
    @RequestMapping(value = "/detail/{orgnazationId}")
    @ResponseBody
    public Object detail(@PathVariable("orgnazationId") Integer orgnazationId) {
        return orgnazationService.selectById(orgnazationId);
    }
}
